const app = getApp();

const request = (params) => {
  return new Promise((resolve, reject) => {
    if(!params.noShowLoading){
      my.showLoading({
        content: '加载中...'
      });
    }
    my.request({
      url: 'https://tyg.zwbysgs.cn/api/' + params.url,
      data: params.data,
      headers: params.headers || {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      method: params.method || 'GET',
      dataType: params.dataType || 'JSON',
      success: function(res) {
        //执行resolve成功操作
        my.hideLoading();
        if(res.data.code == 1){
          resolve(res.data)
        }else{
        //执行reject失败操作
          reject(res.data)
        }
      },
      fail: function(e) {
        my.hideLoading();
        my.showToast({
          content: "网络请求错误"
        })
        reject(e)
      }
    })
  })
}
module.exports = {
  request: request
}